<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@page import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
	String oid=request.getParameter("id");
	String year=request.getParameter("year");
	String month=request.getParameter("month");
	String date=request.getParameter("date");
	String oids=request.getParameter("ids");
	String years=request.getParameter("years");
	String months=request.getParameter("months");
	String dates=request.getParameter("dates");
	String oftime=year+'-'+month+'-'+date;  //开始时间
	String oetime=years+'-'+months+'-'+dates; //结束时间
	
%>
<%
	try{
		String driverName="com.mysql.jdbc.Driver";
		String url="jdbc:mysql://localhost:3306/hotel";
		String userName="root";
		String passWord="root";
		
		Class.forName(driverName);
		Connection con=DriverManager.getConnection(url,userName,passWord);
		//String sql="select * form oinfo";
		String sql="insert into oinfo(rgid,ftime,etime) values (?,?,?);";
		PreparedStatement pstat=con.prepareStatement(sql);
		//ResultSet rs=pstat.executeQuery(); //执行查询
		pstat.setString(1, oid);
		pstat.setString(2, oftime);
		pstat.setString(3, oetime);
		int num=pstat.executeUpdate();
		if(num>0){ //插入数据，同时把订单传到后台处理表
			Connection con2=DriverManager.getConnection(url,userName,passWord);
			String sql2="insert into olist(oname) values (?);";
			PreparedStatement ps=con2.prepareStatement(sql2);
			ps.setString(1, session.getAttribute("userName").toString());
			int num2=ps.executeUpdate();
			if(num2>0){
				response.sendRedirect("index.jsp");
			}
						
		}else{
			out.print("订单添加失败");
		}
	}catch(Exception e){
		e.printStackTrace();
	}
%>
</body>
</html>